<template>
  <div>
    <el-dialog :visible.sync="$parent.uploadVisible" title="导入期刊" width="400px"
               @closed='closedDialog'>
      <el-upload ref="upload"
                 :action="'/pmph/action/journal/uploadAndParse?journalId=' + journalId" accept=".zip"
                 :clearFiles="clearFiles"
                 :on-success="onSuccess" :on-progress="pro" class="upload-demo" drag multiple
                 style='text-align:center;'>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">仅支持扩展名为.zip的文件</div>
      </el-upload>

      <span class="dialog-footer" slot="footer">
        <el-button @click="closedDialog">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: ['uploadVisible'],
  data() {
    return {
      journalId: '',
      bookSourceFileList: [],
      percentage: 20,
      customColor: '#409eff',
      customColors: [
        {color: '#f56c6c', percentage: 20},
        {color: '#e6a23c', percentage: 40},
        {color: '#5cb87a', percentage: 60},
        {color: '#1989fa', percentage: 80},
        {color: '#6f7ad3', percentage: 100}
      ]
    }
  },
  methods: {
    clearFiles: function () {
      this.clearFiles();
    },
    onSuccess: function (response, file, fileList) {
      this.$parent.getTableData();
      this.$parent.timer = setInterval(this.$parent.getTableData, 3000);
      if (fileList.filter(item => item.status === 'uploading').length === 0) {
        this.$parent.uploadVisible = false;
      }
    },
    pro: function () {
      if (this.percentage < 30) {
        return '#909399';
      } else if (this.percentage < 70) {
        return '#e6a23c';
      } else {
        return '#67c23a';
      }
    },

    beforeRemove: function (file, fileList) {
      this.$confirm('是否删除文件？', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功！'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    closedDialog() {
      this.$parent.uploadVisible = false;
    }
  },
}
</script>
<style scoped>
.zZindex {
  z-index: 3000 !important;
}
</style>
